package elsa.bootmapper;

import elsa.bean.ScsTree;
import elsa.bean.ScsStatute;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StatuteMapper {

    //查询树节点(id)
    @Select("select id, name, pid from scs_tree where id = #{id,jdbcType=VARCHAR}")
    List<ScsTree> findById(String id);

    //查询树节点(pid)
    @Select("select id, name, pid from scs_tree where pid = #{pid,jdbcType=VARCHAR}")
    List<ScsTree> findByPid(String pid);

    //新增树节点
    @Insert("insert into scs_tree (id, name, pid) values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR})")
    void saveTree(ScsTree scsTree);

    //更新树节点
    @Update("update scs_tree set name = #{name,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}")
    void updateTree(ScsTree scsTree);

    //删除树节点
    @Delete("delete from scs_tree where id = #{id,jdbcType=VARCHAR}")
    void deleteTree(String id);

    //查询法规条数(parentid)
    @Select("select count(*) from scs_statute where parentid = #{parentid,jdbcType=VARCHAR}")
    int findStatuteCount(String parentid);

    //查询法规列表(parentid)
    @Select("select statuteid, statuteurl, statutename, uploader, uploadtime from scs_statute where parentid = #{parentid,jdbcType=VARCHAR} order by uploadtime desc")
    List<ScsStatute> findStatute(String parentid);

    //查询法规
    @Select("select * from scs_statute where statuteid = #{statuteid,jdbcType=VARCHAR}")
    ScsStatute findStatuteInfo(String statuteid);

    //新建法规
    @Insert("insert into scs_statute (statuteid, parentid, statutename, statuteurl, uploader, uploadtime) values (#{statuteid,jdbcType=VARCHAR}, #{parentid,jdbcType=VARCHAR}, #{statutename,jdbcType=VARCHAR}, #{statuteurl,jdbcType=VARCHAR}, #{uploader,jdbcType=VARCHAR}, #{uploadtime})")
    void saveStatute(ScsStatute scsStatute);

    //删除法规
    @Delete("delete from scs_statute where statuteid = #{statuteid,jdbcType=VARCHAR}")
    void deleteStatute(String statuteid);
}
